﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
#if DOT_NET
using Microsoft.VisualStudio.TestTools.UnitTesting;
#else
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
#endif
using StyleMVVM.Data.Activation;
using StyleMVVM.UnitTests.TestClasses.SimpleObjects;

namespace StyleMVVM.UnitTests.Data
{
	[TestClass]
	public class ActivationServiceTests : BaseTestClass
	{
		[TestMethod]
		public void CreateTest()
		{
			ActivationService activationService = new ActivationService(Container);

			ExportTestInterface export = activationService.Create<ExportTestInterface>();

			Assert.IsNotNull(export);
			Assert.IsNotNull(export.SimpleImport);
		}

		[TestMethod]
		public void SimpleClonetest()
		{
			ActivationService activationService = new ActivationService(Container);

			ExportTestInterface export = activationService.Create<ExportTestInterface>();

			export.A = 42;
			export.SimpleImport.TestString = "Test String";
			export.SimpleImport.TestType = new SimpleType { TestInt = 54 };

			ExportTestInterface clonedExport = activationService.DeepClone<ExportTestInterface>(export);

			Assert.IsNotNull(clonedExport);
			Assert.IsNotNull(clonedExport.SimpleImport);
			Assert.IsNotNull(clonedExport.SimpleImport.TestType);

			Assert.AreNotEqual(export, clonedExport);
			Assert.AreNotEqual(export.SimpleImport, clonedExport.SimpleImport);
			Assert.AreNotEqual(export.SimpleImport.TestType, clonedExport.SimpleImport.TestType);

			Assert.AreEqual(export.A, clonedExport.A);
			Assert.AreEqual(export.SimpleImport.TestString, clonedExport.SimpleImport.TestString);
			Assert.AreEqual(export.SimpleImport.TestType.TestInt, clonedExport.SimpleImport.TestType.TestInt);
		}

		[TestMethod]
		public void CloneWithContainerstest()
		{
			ActivationService activationService = new ActivationService(Container);

			CloneTestType1 newType1 =
				new CloneTestType1
					{
						Clone2List = new List<CloneTestType2>()
					};

			CloneTestType2 newType2I1 = new CloneTestType2 { Clone3s = new Dictionary<string, CloneTestType3>() };
			CloneTestType2 newType2I2 = new CloneTestType2 { Clone3s = new Dictionary<string, CloneTestType3>() };

			newType1.Clone2List.Add(newType2I1);
			newType1.Clone2List.Add(newType2I2);

			string helloString = "Hello";
			string testString = "Test String";

			CloneTestType3 newType3SHello = new CloneTestType3 { TestValue = helloString };
			CloneTestType3 newtype3STestString = new CloneTestType3 { TestValue = testString };

			newType2I1.Clone3s.Add(helloString, newType3SHello);
			newType2I2.Clone3s.Add(testString, newtype3STestString);

			CloneTestType1 cloneTestType1 =
				activationService.DeepClone<CloneTestType1>(newType1);

			Assert.IsNotNull(cloneTestType1);
			Assert.IsNotNull(cloneTestType1.Clone2List);

			Assert.AreEqual(2, cloneTestType1.Clone2List.Count);

			CloneTestType2 clone2 = cloneTestType1.Clone2List[0];
			CloneTestType2 clone2A = cloneTestType1.Clone2List[1];

			Assert.IsNotNull(clone2);
			Assert.IsNotNull(clone2A);

			Assert.IsNotNull(clone2.Clone3s);
			Assert.IsNotNull(clone2A.Clone3s);

			CloneTestType3 clone3 = clone2.Clone3s[helloString];
			CloneTestType3 clone3A = clone2A.Clone3s[testString];

			Assert.IsNotNull(clone3);
			Assert.IsNotNull(clone3A);

			Assert.AreEqual(helloString, clone3.TestValue);
			Assert.AreEqual(testString, clone3A.TestValue);
		}

		[TestMethod]
		public void CloneArrayTest()
		{
			ActivationService activationService = new ActivationService(Container);

			CloneTestType1 newType1 =
				new CloneTestType1 { TestArray = new int[5] };

			CloneTestType1 clone1 = activationService.DeepClone<CloneTestType1>(newType1);
		}
	}
}